package cn.lili.modules.member.client;

import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.constant.ServiceConstant;
import cn.lili.modules.member.entity.dos.CityDistribution;
import cn.lili.modules.member.entity.dos.User;
import cn.lili.modules.member.entity.dto.UserInfoDTO;
import cn.lili.modules.member.entity.dto.UserLoginDTO;
import cn.lili.modules.member.entity.dto.UserSearchParams;
import cn.lili.modules.member.entity.vo.UserVO;
import cn.lili.modules.member.fallback.UserFallback;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencentcloudapi.ecm.v20190719.models.City;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户服务client
 *
 * @author liushuai(liushuai711 @ gmail.com)
 * @since 2021/12/7 08:23
 */
@FeignClient(path = "${server.servlet.context-path}", name = ServiceConstant.USER_SERVICE, contextId = "user", fallback = UserFallback.class)
public interface UserClient {


    /**
     * 查询用户
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/feign/user/query")
    User getById(@RequestParam String id);

    /**
     * 查询用户
     *
     * @param mobile 手机号
     * @param scene  场景
     * @return 用户
     */
    @GetMapping("/feign/user/query/mobile")
    User getByMobile(@RequestParam String mobile, @RequestParam SceneEnums scene);

    /**
     * 获取指定用户数据
     *
     * @param columns   指定获取的列
     * @param memberIds 用户ids
     * @return 指定用户数据
     */
    @GetMapping("/feign/user/query/field")
    List<Map<String, Object>> listFieldsByMemberIds(@RequestParam String columns, @RequestParam List<String> memberIds);

    /**
     * 获取所有用户的手机号
     *
     * @return 所有用户的手机号
     */
    @GetMapping("/feign/user/mobile")
    List<String> getAllMemberMobile();

    /**
     * 根据条件查询用户总数
     *
     * @param userSearchParams 查询参数
     * @return 用户总数
     */
    @PostMapping("/feign/user/getMemberNum")
    long getUserNum(@RequestBody UserSearchParams userSearchParams);

    /**
     * 根据条件查询用户列表
     *
     * @param searchParams 查询参数
     * @return 用户列表
     */
    @PostMapping("/feign/user/list")
    List<User> list(@RequestBody UserSearchParams searchParams);

    /**
     * 更新用户登录时间为最新时间
     *
     * @param userId 用户id
     * @return 是否更新成功
     */
    @PutMapping("/feign/user/updateUserLoginTime")
    Boolean updateUserLoginTime(@RequestParam String userId);


    /**
     * 用户登录 账号密码+场景查询用户
     *
     * @param userLoginDTO 查询参数
     * @return 用户
     */
    @PostMapping("/feign/user/login/query")
    User queryUser(@RequestBody UserLoginDTO userLoginDTO);

    /**
     * 用户登录 账号密码+场景查询用户
     *
     * @param mobile 手机号
     * @param scene  场景
     * @return 用户
     */
    @GetMapping("/feign/user/mobile/query")
    User mobilePhoneLogin(@RequestParam String mobile, @RequestParam SceneEnums scene);

    /**
     * 注册用户
     *
     * @param userInfoDTO 用户注册
     * @return 用户
     */
    @PostMapping("/feign/user/regist")
    User register(@RequestBody UserInfoDTO userInfoDTO);


    /**
     * 标记短信验证成功，用于修改密码前缀
     *
     * @param scene  标记场景
     * @param mobile 标记手机号
     * @param uuid   标记uuid
     */
    @PostMapping("/feign/user/sms/sign")
    void resetPasswordSign(@RequestParam String uuid, @RequestParam String mobile, @RequestParam SceneEnums scene);


    /**
     * 执行密码修改
     *
     * @param scene    场景
     * @param password 密码
     * @param uuid     uuid
     */
    @PostMapping("/feign/user/resetPasswordByMobile")
    Boolean resetPasswordByMobile(@RequestParam String uuid, @RequestParam String password, @RequestParam SceneEnums scene);

    @GetMapping("/feign/user/info")
    UserVO info();

    /**
     * 生成用户
     * @param user 用户信息
     * @return
     */
    @PostMapping("/feign/user/generateUser")
    User generateUser(@RequestBody User user);

    /**
     * 根据扩展ID获取用户信息
     * @param extId 扩展ID
     * @return
     */
    @GetMapping("/feign/user/getByExtId")
    User getByExtId(@RequestParam String extId);

    /**
     * 根据扩展ID获取用户信息  多个绑定信息情况处理
     * @param extId 扩展ID
     * @return
     */
    @GetMapping("/feign/user/getByExtId2")
    User getByExtId2(@RequestParam String extId);

    @GetMapping("/feign/user/getByOpenId")
    User getByOpenId(@RequestParam String openId,@RequestParam String scene);

    @GetMapping("/feign/user/updateFyById")
    Boolean updateFyById(@RequestParam String openId, @RequestParam String account, @RequestParam  String nickName, @RequestParam String userId,@RequestParam String scene);

    @GetMapping("/feign/user/getByUserName")
    User getByUserName(@RequestParam String account, @RequestParam String scene);



    //删除城市分站
    @GetMapping("/feign/user/delete")
    Boolean deleteUserByExtId(@RequestParam String extId);


    @GetMapping("/feign/user/selectUserListByIds")
    @ApiOperation(value = "根据用户id集合查询用户列表")
    List<User> selectUserListByIds(@RequestParam List<String> userIdList);

    @GetMapping("/feign/usergreen/frozen")
    Boolean userFrozen(@RequestParam String userId,Boolean frozen);

    /**
     * 查询一个fy_开头的openid
     * */
    @GetMapping("/feign/openId/byfy")
    String getOpenIdByFy();

    @PostMapping("/feign/updateUserFyNameAndFaceById")
    @ApiOperation("根据id更新头像和昵称")
    Boolean updateUserFyNameAndFaceById(@RequestBody User user);

    /**
     * 根据id修改，用户
     * @param user
     * @return
     */
    @PostMapping("/feign/updateById")
    Boolean updateById(@RequestBody User user);


    @GetMapping("/feign/selectUserChildCountByUserIds")
    Map<String, Integer> selectUserChildCountByUserIds(@RequestParam List<String> userIds);

    /**
     * 根据店主用户ids查询下级id
     * @return
     */
    @GetMapping("/feign/selectChildUserIdsByMemberIds")
    Map<String, List<String>> selectChildUserIdsByMemberIds(@RequestParam List<String> userIds);

    /**
     * 清除邀请人id
     * @param user
     * @return
     */
    @PostMapping("/feign/removeChildUserRelationship")
    Boolean removeChildUserRelationship(@RequestBody User user);



    @GetMapping("/feign/callGetSubordinatesAndSubSubordinates")
    String callGetSubordinatesAndSubSubordinates(@RequestParam String currentId);


    @GetMapping("/feign/getLowerByParentId")
    List<User> getLowerByParentId(@RequestParam String userId);

    @GetMapping("/feign/getCastellan")
    CityDistribution getCastellan(@RequestParam String regionId);

    /**
     * 获取城主历史数据
     * @param page 页
     * @param size 条
     * @return 历史记录
     */
    @GetMapping("/feign/historyEarnings")
    Page<CityDistribution> historyEarnings(@RequestParam Integer page, @RequestParam Integer size);

    /**
     * 根据区域，年月获取城主
     *
     * @param regionId 区域
     * @param year 年
     * @param month 月
     * @return 城主
     */
    @GetMapping("/feign/getCastellanByCodeYearMonth")
    CityDistribution getCastellanByCodeYearMonth(@RequestParam String regionId, @RequestParam Integer year, @RequestParam Integer month);

    /**
     * 修改用户信息
     * @param user 用户
     * @return 是否成功
     */
    @PostMapping("/feign/updateUserByIdAndMember")
    Boolean updateUserByIdAndMember(@RequestBody User user);

    /**
     * 获取字段
     * @param filed 字段
     * @param filedValue 1字段过滤条件
     */
    @GetMapping("/feign/getListByFiledValue")
    List<User> getListByFiledValue(@RequestParam String filed,@RequestParam String filedValue);

}
